/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.controler;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.net.ssl.SSLServerSocket;

import sharedObjects.FieldStorage;
import sharedObjects.MessageNotification;
import sharedObjects.ObjectWrapper;

/**
 *
 * @author Niclas
 */
public class PackageReceiver extends Thread{

    Socket s;
    @Override
    public void run() {
        super.run();
        ObjectInputStream ois;
        ObjectWrapper ow;
                
        try {
            
            ois = new ObjectInputStream(s.getInputStream());
                while ((ow = (ObjectWrapper) ois.readObject()) != null){
                    if (ow.getObjectType().equals(ObjectWrapper.STATUS_MESSAGE))
                    {
                        MessageNotification mn = (MessageNotification)ow.getGameObject();
                        if (mn.equals(MessageNotification.OK)){
                        System.out.println("Server: OK");
                                }
                        else if (mn.equals(MessageNotification.ERROR)){
                        System.out.println("Server: ERROR");
                                }
                    }
                    if (ow.getObjectType().equals(ObjectWrapper.SHIP_STORAGE)){
                    	LaunchController.getInstance().fieldStorageEnemy = (FieldStorage)(ow.getGameObject());
                    	//sf //??????
                    
                    }
                    
                }
        } catch (IOException ex) {
            Logger.getLogger(PackageReceiver.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (ClassNotFoundException ex) {
                Logger.getLogger(PackageReceiver.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

    public PackageReceiver(Socket s) {
        this.s = s;
        this.start();
    }
    
    
}
